<?php
require_once("./caiji.toutiao.m.db.inc.php");
require_once("./lib/saekv.lib.php");

require_once("./caiji.toutiao.inc.php");
extract($_GET);
extract($_POST);
if (!empty($actfunc)){
	/*
	tasklist_status2normal();
	tasklist_status2old();
	caiji_listgroup();
	*/


	echo "<meta charset=\"UTF-8\">";
	//getruntime();	

	echo "\n";
	$actfunc();
}else{
	ob_start();
	caiji_listgroup();
	$content = ob_get_contents();
	ob_end_clean();
	$content=mb_convert_encoding($content, "GBK", "UTF-8");  
	echo $content;
}

	exit;

//====================================================
function caiji_listgroup(){
	global $A_urls;
	global $A_q_title;
	html_header();
	echo "<base  target=\"viewframe\">";
	foreach($A_urls as $groupname=>$url){
		$rule="://[name]/";
		$host_real=getpregmsg($url,$rule,1);
		if($host_real=="127.0.0.1:8080"){
			$host_real="0.0.0.0:8080";
			$url=str_replace("127.0.0.1:8080",$host_real,$url);
		}
		//echo $groupname.":".$host_real;
		$baseurl="http://$host_real/caiji/";
		echo "<A HREF=\"".$baseurl."caiji.toutiao.m.list.php?dbtype=12&actfunc=tasklist_listword&groupname=$groupname\">$groupname</A>  ";
		echo "<A HREF=\"caiji.toutiao.m.list.php?dbtype=12&actfunc=tasklist_listword&groupname=$groupname\">ip$groupname</A>  ";
		$q_title=$A_q_title[$groupname];
		echo "<a href=\"".$baseurl."caiji.toutiao.m.oneword.export.php?q_title=$q_title&q_timetype=date&q_timecount=1&dbtype=12&groupname=$groupname\">昨天</a> ";

		echo "<a href=\"".$baseurl."caiji.toutiao.m.oneword.export.php?q_title=$q_title&q_timetype=all&q_timecount=1&dbtype=12&groupname=$groupname\">全部</a> ";
		echo "<A HREF=\"\"></A> ";
		//worddelete wordinsert wordlist wordtoutiaos
		echo "<A HREF=\"$url\">00采集</A> ";
		echo "<A HREF=\"caiji.toutiao.m.xv2db.php?dbtype=12&groupname=$groupname\">ip采集</A> ";
		echo "<br>\n";
	}
	$json=saekvget("groupnamelist");
	$arr=json_decode($json,1);
	foreach($arr as $groupname=>$val){
		echo "<A HREF=\"caiji.toutiao.m.list.php?dbtype=12&actfunc=tasklist_listword&groupname=$groupname\">$groupname </A> ";
	}
	?>
<form method=get>
<input type=text name=groupname size=20>
<input type=hidden name=actfunc value=addgroup size=20>
<input type=submit>
</form>
	<?
}
function addgroup(){
	extract($_GET);
	$json=saekvget("groupnamelist");
	$arr=json_decode($json,1);
	$arr[$groupname]=1;
	print_r($arr);
	$json=json_encode($arr);
	saekvset("groupnamelist",$json);
}
function tasklist_status2old(){
	//delete word not to fetch or display
	global $DB_tasklist,$DB_toutiaom;
	extract($_GET);
	echo
	$sql="update tasklist set status='old' where word='$word'";
	$DB_tasklist->query($sql);
	$sql="update toutiaom set status='old' where word='$word'";
	$DB_toutiaom->query($sql);
}

function tasklist_status2normal(){
	global $DB_tasklist,$DB_toutiaom;
	extract($_GET);
	echo
	$sql="update tasklist set status='0' where word='$word'";
	$DB_tasklist->query($sql);
	$sql="update toutiaom set status='0' where word='$word'";
	$DB_toutiaom->query($sql);
}
function tasklist_add1word(){
	global $DB_tasklist,$DB_toutiaom;
	tbl_create_tasklist();//初始化
	tbl_create_toutiaom();//初始化
	extract($_GET);
	extract($_POST);
	echo $groupname;
	//echo $word;
	$word=str_replace("\r","",$word);
	$aword=explode("\n",$word);
	foreach ($aword as $word){
	$word=strtolower(trim($word));
	if(!empty($word))
	 $A_all[]=compact(word,groupname);
	}
	//print_r($A_all);
	data2sql($A_all,"tasklist",$DB_tasklist);
}

function tasklist_show1word(){
	global $DB_tasklist,$DB_toutiaom;
	extract($_GET);
	ob_clean();
	html_header();
	extract($_GET);
	$sql="select * from tasklist where  word='$word'";
	$A_row=$DB_toutiaom->queryrow($sql);
	extract($A_row);
	$keyword=$word;
	//$url_pre="caiji.toutiao.splitword.export.php?dbtype=12&groupname=$groupname&keyword=$keyword&firstkeyword=$keyword&word=$word&";
	$url_pre="caiji.toutiao.splitword.export.php?dbtype=12&groupname=$groupname&keyword=$keyword&firstkeyword=$keyword&";
	$link1="<A title=\"查看对应的关键词分类\" HREF=\"".$url_pre."action=listalltag\">关键词</A>";
	$link1.=" <A title=\"重新查看对应的关键词分类\" HREF=\"".$url_pre."action=listalltag&tags_reget=1\">重查关键词</A>";
	$link_fenci1="<A HREF=\"".$url_pre."action=tagword_fenlei\">分词统计</A>";
	$link_fenci2="<A HREF=\"".$url_pre."action=tagword_fenlei&restart=1\">分词统计重启</A>";
$url_pre_md="caiji.toutiao.export.md.php?dbtype=12&groupname=$groupname&keyword=$keyword&firstkeyword=$keyword&";
	$link_fenci3="<A HREF=\"".$url_pre_md."action=show_tagresult&q_order=ID\">统计导出md</A> ";
	$link_fenci3.="<A HREF=\"".$url_pre."action=show_tagresult&q_order=ID\">统计导出</A> ";
	$link_fenci3.="<A HREF=\"".$url_pre."action=show_tagresult&q_order=ID desc\">导出倒序</A> ";
	$link_fenci3.="<A HREF=\"".$url_pre."action=show_tagresult&q_order=grade desc\">统计分级</A> ";
	$link_fenci3.="<A HREF=\"".$url_pre."action=show_tagresult&q_order=total desc\">统计总数</A> ";
	//$url_pre="?dbtype=12&groupname=$groupname&word=$word&";
	$url_pre="?dbtype=12&groupname=$groupname";
	$link_fenci4="<A HREF=\"caiji.toutiao.splitword.php".$url_pre."action=tagword_fenlei\">分词</A> ";

	echo "$word <br> $link1  $link_fenci1 $link_fenci2 $link_fenci3 $link_fenci4 ";
?>

<br>
普通：
<a href="caiji.toutiao.m.oneword.export.php<?=$url_pre;?>q_timetype=date&q_timecount=1">昨天</a>
<a href="caiji.toutiao.m.oneword.export.php<?=$url_pre;?>q_timetype=week&q_timecount=1">上周</a>
<a href="caiji.toutiao.m.oneword.export.php<?=$url_pre;?>q_timetype=month&q_timecount=1">上月</a>
<a href="caiji.toutiao.m.oneword.export.php<?=$url_pre;?>q_timetype=all&q_timecount=1">所有</a>

<br>

<?
	html_form_except();
}
function tasklist_listword(){
	global $DB_toutiaom,$groupname;
	$word=$_GET["word"];
	$whereword=empty($word)?" 1=1 ":" word='$word' ";
	$sql="select * from tasklist order by ID limit 0,100";
	$A_all1=$DB_toutiaom->queryall($sql);
	$sql="select * from tasklist order by ID desc limit 0,10";
	$A_all2=$DB_toutiaom->queryall($sql);
	$A_all=array_merge($A_all1,$A_all2);
	//getruntime();	
	_tasklist_listword_form($groupname);
	foreach($A_all as $A_row ){
		extract($A_row);

		$link_status=($status=="old")?"<A HREF=\"caiji.toutiao.m.list.php?dbtype=12&groupname=$groupname&actfunc=tasklist_status2normal&word=$word\">$status</A> ":"<A HREF=\"caiji.toutiao.m.list.php?dbtype=12&groupname=$groupname&actfunc=tasklist_status2old&word=$word\">$status</A> ";
		$link_zhuanfa="<a href=\"caiji.toutiao.m.oneword.export.php?q_word=$word&q_timetype=all&q_timecount=1&dbtype=12&groupname=$groupname&postmode=zhuanfa&q_extrawhere= and 1=1\">普通</a> ";
		$link_show1word="<a href=\"caiji.toutiao.m.list.php?dbtype=12&groupname=$groupname&actfunc=tasklist_show1word&word=$word\">$word</a> ";
		$link_makekeyword="<a href=\"caiji.toutiao.splitword.export.php?dbtype=12&groupname=$groupname&action=makekeyword&prekeyword=$word\">keyword</a>";
		echo " $link_show1word  $link_zhuanfa $link_status	$pagetype	$ufans $pagenbr $link_makekeyword<br>\n";
	}
	//getruntime();	
	
}


function tag_list1tag(){
	extract($_GET);
	ob_clean();
	html_header();
	$url_pre="?dbtype=12&groupname=$groupname&keyword=$keyword&firstkeyword=$keyword&";
	echo $keyword;
?>
<br>
		<A HREF="caiji.toutiao.splitword.export.php<?=$url_pre;?>action=tagword_fenlei">分词统计</A>
		<A HREF="caiji.toutiao.splitword.export.php<?=$url_pre;?>action=tagword_fenlei&restart=1" title="分词统计重启">统计重启</A>
		<A HREF="caiji.toutiao.export.md.php<?=$url_pre;?>action=md_1word_test">导出test</A> 
		<A HREF="caiji.toutiao.export.md.php<?=$url_pre;?>action=md_1word_restart">导出restart</A> 
		<A HREF="caiji.toutiao.export.md.php<?=$url_pre;?>action=md_1word_continue">导出continue</A> 
		<A HREF="caiji.toutiao.export.md.php<?=$url_pre;?>action=">导出hot</A> 
<br>
		<A HREF="caiji.toutiao.m.oneword.export.php<?=$url_pre;?>q_timetype=all&q_timecount=0&q_page=1&q_size=50&ID_start=1&q_title=<?=$keyword;?>"><?=$keyword;?> 查微博</A>
		<A HREF="caiji.toutiao.splitword.export.php<?=$url_pre;?>action=show_tagresult&q_order=ID">统计导出</A> 

		<A HREF="caiji.toutiao.splitword.export.php<?=$url_pre;?>action=show_tagresult&q_order=ID desc">导出倒序</A> 
		<A HREF="caiji.toutiao.splitword.export.php<?=$url_pre;?>action=show_tagresult&q_order=grade desc">统计分级</A> 
		<A HREF="caiji.toutiao.splitword.export.php<?=$url_pre;?>action=show_tagresult&q_order=total desc">统计总数</A> 



<?
}
function _tasklist_listword_form($groupname){
	ob_clean();
	html_header();
	$url_pre="?dbtype=12&groupname=".$groupname."&";
	global $A_q_title;
	$q_title=$A_q_title[$groupname];
$basedir=dirname($_SERVER["SCRIPT_NAME"]);
$url_fetch = "http://".$_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"];
echo 
$url_fetch.= $basedir."/caiji.toutiao.m.xv2db.php?groupname=$groupname";
$url_fetch=urlencode($url_fetch);


?>
	<A HREF="caiji.toutiao.m.xv2db.php<?=$url_pre;?>">采集</A> 
	<A HREF="cron.php?url_fetch=<?=$url_fetch;?>">cron采集</A> 
	<A HREF="caiji.toutiao.m.oneword.restart.php<?=$url_pre;?>">重启后采集</A> 
<br>
<a href="caiji.toutiao.splitword.php<?=$url_pre;?>">分词</a>
<a href="caiji.toutiao.splitword.export.php<?=$url_pre;?>action=tagword_fenlei&restart=1">分词统计重启</a>
<a href="caiji.toutiao.splitword.export.php<?=$url_pre;?>action=tagword_fenlei">分词统计</a>
<a href="caiji.toutiao.splitword.export.php<?=$url_pre;?>action=show_tagresult">分词统计导出</a>
<a href="caiji.toutiao.splitword.export.php<?=$url_pre;?>action=tagword_deltag">分词冗余清理</a>
<a href="caiji.toutiao.splitword.export.php<?=$url_pre;?>action=listalltag">显示关键词</a>
<a href="caiji.toutiao.splitword.export.php<?=$url_pre;?>action=makekeyword">生成搜索关键词</a>
<a href="caiji.toutiao.splitword.export.php<?=$url_pre;?>action=listalltag&tags_reget=1">重新统计关键词</a>

<a href="caiji.toutiao.export.md.php<?=$url_pre;?>action=listalltag&tags_reget=1">导出markdown</a>


<a href="caiji.toutiao.splitword.export.php<?=$url_pre;?>action=listauthor2tag">用户列表</a>
<a href="caiji.toutiao.splitword.export.php<?=$url_pre;?>action=show_toutiaodetail&tbl=tagword_深圳_最大_城市&word=房价">词查微博</a>
<a href="caiji.toutiao.splitword.export.php?action=test_check_node_type">测试节点</a>
<br>

普通
<a href="caiji.toutiao.m.oneword.export.php<?=$url_pre;?>q_title=<?=$q_title;?>&q_timetype=date&q_timecount=1">昨天</a>
<a href="caiji.toutiao.m.oneword.export.php<?=$url_pre;?>q_title=<?=$q_title;?>&q_timetype=week&q_timecount=1">上周</a>
<a href="caiji.toutiao.m.oneword.export.php<?=$url_pre;?>q_title=<?=$q_title;?>&q_timetype=month&q_timecount=1">上月</a>
<a href="caiji.toutiao.m.oneword.export.php<?=$url_pre;?>q_title=<?=$q_title;?>&q_timetype=all&q_timecount=1">所有</a>
<br>
短链：
<a href="caiji.toutiao.m.oneword.export.php<?=$url_pre;?>q_title=<?=$q_title;?>&q_timetype=date&q_timecount=1&postmode=duanlian">昨天</a>

<br>
<?html_form_except();?>

<FORM METHOD="get" ACTION="caiji.toutiao.m.list.php" name="formword">
<INPUT TYPE="hidden" NAME="word1" value="" style="width:140px">
<textarea name="word" rows="4" cols=""></textarea>
<INPUT TYPE="hidden" NAME="groupname" value="<?=$groupname;?>" style="width:100px">
<INPUT TYPE="hidden" NAME="actfunc" value="tasklist_add1word">
<INPUT TYPE="hidden" NAME="dbtype" value="12">
<INPUT TYPE="submit" name="action1" title="12 add " value="toutiaom add1word" onclick="document.formword.mod.value='toutiaom';document.formword.dbtype.value='12';">
(头条搜索英文两词组合不能用空格，要用/)
</FORM>
<?}


function html_header(){
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><meta http-equiv="Cache-Control" content="no-cache"/><meta id="viewport" name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0, maximum-scale=2.0" /><meta name="MobileOptimized" content="240"/><title><?=$_GET["groupname"]?></title><style type="text/css" id="internalStyle">html,body,p,form,div,table,textarea,input,span,select{font-size:16px;word-wrap:break-word;}body{background:#F8F9F9;color:#000;padding:1px;margin:1px;}table,tr,td{border-width:0px;margin:0px;padding:0px;}form{margin:0px;padding:0px;border:0px;}textarea{border:1px solid #96c1e6}textarea{width:95%;}a,.tl{color:#2a5492;text-decoration:underline;}/*a:link {color:#023298}*/.k{color:#2a5492;text-decoration:underline;}.kt{color:#F00;}.ib{border:1px solid #C1C1C1;}.pm,.pmy{clear:both;background:#ffffff;color:#676566;border:1px solid #b1cee7;padding:3px;margin:2px 1px;overflow:hidden;}.pms{clear:both;background:#c8d9f3;color:#666666;padding:3px;margin:0 1px;overflow:hidden;}.pmst{margin-top: 5px;}.pmsl{clear:both;padding:3px;margin:0 1px;overflow:hidden;}.pmy{background:#DADADA;border:1px solid #F8F8F8;}.t{padding:0px;margin:0px;height:35px;}.b{background:#e3efff;text-align:center;color:#2a5492;clear:both;padding:4px;}.bl{color:#2a5492;}.n{clear:both;background:#436193;color:#FFF;padding:4px; margin: 1px;}.nt{color:#b9e7ff;}.nl{color:#FFF;text-decoration:none;}.nfw{clear:both;border:1px solid #BACDEB;padding:3px;margin:2px 1px;}.s{border-bottom:1px dotted #666666;margin:3px;clear:both;}.tip{clear:both; background:#c8d9f3;color:#676566;border:1px solid #BACDEB;padding:3px;margin:2px 1px;}.tip2{color:#000000;padding:2px 3px;clear:both;}.ps{clear:both;background:#FFF;color:#676566;border:1px solid #BACDEB;padding:3px;margin:2px 1px;}.tm{background:#feffe5;border:1px solid #e6de8d;padding:4px;}.tm a{color:#ba8300;}.tmn{color:#f00}.tk{color:#ffffff}.tc{color:#63676A;}.c{padding:2px 5px;}.c div a img{border:1px solid #C1C1C1;}.ct{color:#9d9d9d;font-style:italic;}.cmt{color:#9d9d9d;}.ctt{color:#000;}.cc{color:#2a5492;}.nk{color:#2a5492;}.por {border: 1px solid #CCCCCC;height:50px;width:50px;}.me{color:#000000;background:#FEDFDF;padding:2px 5px;}.pa{padding:2px 4px;}.nm{margin:10px 5px;padding:2px;}.hm{padding:5px;background:#FFF;color:#63676A;}.u{margin:2px 1px;background:#ffffff;border:1px solid #b1cee7;}.ut{padding:2px 3px;}.cd{text-align:center;}.r{color:#F00;}.g{color:#0F0;}.bn{background: transparent;border: 0 none;text-align: left;padding-left: 0;}</style></head><body>

<?
}



?>
